<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
  <input type="hidden" id="id" name="id" value="${information.id}" />
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input type="text"  class="layui-input name" id="title" name="title" value="${information.title}" placeholder="请输入标题" lay-verify="required">
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">目录名称</label>
    <div class="layui-input-block">
      <select class="form-control" name="catalogId" id="catalogId">
        <#list list as catalog>
          <option value="${catalog.id}" <#if catalog.id==information.catalogId>selected</#if>>${catalog.name}</option>
        </#list>
      </select>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">图片</label>
    <div class="layui-input-block">
      <div class="famous-upload-pic">
        <img  <#if information.showPic?if_exists  >src="${information.showPic}"<#else>src="${s.base}/image/icon_addpic.png"</#if> class="upload-avatar" id="upload-avatar"/>
        <input type="file" name="myfiles" class="upload" id="myFile" onchange="ajaxFileUploads('myFile','showPic','upload-avatar')">
        <input type="hidden" class="image" name="showPic" id="showPic" <#if information.showPic?if_exists  > value="${information.showPic}"  <#else> value="/image/icon_addpic.png" </#if> />
      </div>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">文章描述</label>
    <div class="layui-input-block">
      <textarea id="description" name="description" style="width: 100%; height: 200px;">${information.description}</textarea>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">文章内容</label>
    <div class="layui-input-block">
      <div id="content">
        ${information.content}
      </div>
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input name" id="sort" name="sort" value="${information.sort}" placeholder="请输入排序" maxlength="30" lay-verify="required">
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">有效状态</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="1" title="有效" <#if !(information.status?if_exists&&information.status=='2')>checked</#if>>
      <input type="radio" name="status" value="2" title="无效" <#if information.status?if_exists&&information.status=='2'>checked</#if>>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">首页展示</label>
    <div class="layui-input-block">
      <input type="radio" name="showFrist" value="2" title="否" <#if !(information.showFrist?if_exists&&information.showFrist=='1')>checked</#if>>
      <input type="radio" name="showFrist" value="1" title="是" <#if information.showFrist?if_exists&&information.showFrist=='1'>checked</#if>>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="btnSubmit">确定</button>
      <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary closeLay">取消</button>
    </div>
  </div>
</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/wangEditor/wangEditor.js"></script>
<script type="text/javascript" src="${s.base}/js/base/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="${s.base}/js/base/ajaxfileupload.js"></script>
<script>
  var E = window.wangEditor;
  var editor = new E('#content');
  editor.customConfig.uploadFileName = 'myfiles';
  editor.customConfig.uploadImgServer = '/file/fileUploadEditor';
  editor.create();

  var content = $("#contentValue").val();
  editor.txt.html(content);

  layui.use(['form','layer'],function(){
      var form = layui.form
      layer = parent.layer === undefined ? layui.layer : top.layer,
          $ = layui.jquery;
      form.on("submit(btnSubmit)",function(data){
          //弹出loading
          var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
          var field = data.field;
          var status = field.status;
          var content = editor.txt.html();
          data.field.content=content;
          // 实际使用时的提交信息
          $.post("/information/updateOrAddEntity",data.field,function(result){
              if(1==result.returnInfo.state){
                  top.layer.close(index);
                  top.layer.msg("操作成功！");
                  layer.closeAll("iframe");
                  //刷新父页面
                  parent.location.reload();
              }else{
                  top.layer.msg(result.returnInfo.errorMsg);
              }
          },"json")
          return false;
      });
  })
</script>
</body>
</html>